using System;
using System.Collections.Generic;
using System.Text;

namespace Deepcode.Flux.Core.UI.Abstract
{
	/// <summary>
	/// Setupwizard base implements the standard UserControl base class for wizard panels
	/// that need error reporting captability. Your ascx implementation must override the two
	/// properties Base_ErrorContainer and Base_ErrorLabel to specify which panel and label controls
	/// should be used to display error messages.
	/// 
	/// Also override Initialise and FinishForm to specify the handling logic for the form load and form save
	/// 
	/// Use DoLocalError() to report errors to the user.
	/// </summary>
	public abstract class SetupWizardBase : System.Web.UI.UserControl, Deepcode.Flux.Core.UI.Interfaces.IWizardPane
	{
		protected virtual System.Web.UI.WebControls.Panel Base_ErrorContainer{ get { return null; } }
		protected virtual System.Web.UI.WebControls.Label Base_ErrorLabel{ get { return null; } }

		/// <summary>
		/// IWizardPane Initialise base implementation
		/// </summary>
		/// <param name="settings"></param>
		public virtual void Initialise(Deepcode.Flux.Core.Collections.BaseDictionary settings)
		{
			ClearErrorConditions();
		}
		/// <summary>
		/// IWizardPane Finishform base implementation
		/// </summary>
		/// <param name="settings"></param>
		/// <returns></returns>
		public virtual bool FinishForm(Deepcode.Flux.Core.Collections.BaseDictionary settings)
		{
			return true;
		}
		/// <summary>
		/// Clears any error conditions that are outstanding - auto called by initialise
		/// </summary>
		protected void ClearErrorConditions()
		{
			Base_ErrorContainer.Visible = false;
		}
		/// <summary>
		/// Displays an error message. DoLocalError also returns false so that it can be
		/// used to return false in the calling function. (So you don't have to 
		/// create a code block to do the error then return from the function).
		/// </summary>
		/// <param name="ErrorMessage"></param>
		/// <returns></returns>
		protected bool DoLocalError(string ErrorMessage)
		{
			Base_ErrorLabel.Text = "<font color=red>";
			Base_ErrorLabel.Text += "<b>Please correct the following error:</b><br/>";
			Base_ErrorLabel.Text += ErrorMessage + "</font>";
			Base_ErrorContainer.Visible = true;
			return false;
		}
	}

}
